# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


class LagouPipeline:
    def open_spider(self,spider):
        #创建my.txt文件，并将字符集设为utf-8
        self.file = open('/Users/mym/Desktop/scrapy/lagou/data.txt', 'w', encoding='utf-8') 
    
    def close_spider(self,spider):
        self.file.close()

    def process_item(self, item, spider):

        datas=item["datas"]
        for item in datas:
            title=item["title"]
            salary=item["salary"]
            company=item["company"]
            # sprintf("%d" 123)
            # \n 换行符
            line="{},{},{}\n".format(title,salary,company)
            self.file.write(line)


        # return item
